{% extends "base.html" %}

{% block content %}
<div class="row">
    <div class="col-md-12 mb-4">
        <div class="d-flex justify-content-between align-items-center">
            <h2>编辑用户</h2>
            <a href="{{ url_for('admin.users') }}" class="btn btn-outline-primary">返回用户列表</a>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">编辑用户信息</h5>
            </div>
            <div class="card-body">
                <form action="" method="post" novalidate>
                    {{ form.hidden_tag() }}
                    <div class="mb-3">
                        {{ form.name.label(class="form-label") }}
                        {{ form.name(class="form-control") }}
                        {% for error in form.name.errors %}
                        <div class="text-danger">{{ error }}</div>
                        {% endfor %}
                    </div>
                    
                    <div class="mb-3">
                        {{ form.role.label(class="form-label") }}
                        {{ form.role(class="form-select") }}
                        {% for error in form.role.errors %}
                        <div class="text-danger">{{ error }}</div>
                        {% endfor %}
                    </div>
                    
                    <div class="d-flex justify-content-between">
                        <a href="{{ url_for('admin.users') }}" class="btn btn-outline-secondary">取消</a>
                        {{ form.submit(class="btn btn-primary") }}
                    </div>
                </form>
            </div>
        </div>
    </div>
    
    <div class="col-md-4">
        <div class="card">
            <div class="card-header bg-secondary text-white">
                <h5 class="mb-0">用户信息</h5>
            </div>
            <div class="card-body">
                <p><strong>用户名:</strong> {{ user.username }}</p>
                <p><strong>当前姓名:</strong> {{ user.name }}</p>
                <p><strong>当前角色:</strong> {{ '管理员' if user.role == 'admin' else '成员' }}</p>
                <p><strong>注册时间:</strong> {{ user.created_at.strftime('%Y-%m-%d') }}</p>
                <p><strong>文章数:</strong> {{ user.articles|length }}</p>
                <p><strong>技能数:</strong> {{ user.skills|length }}</p>
                
                <div class="mt-3">
                    <a href="{{ url_for('users.profile', id=user.id) }}" class="btn btn-outline-primary">查看用户档案</a>
                </div>
            </div>
        </div>
        
        {% if user.id != current_user.id %}
        <div class="card mt-4">
            <div class="card-header bg-danger text-white">
                <h5 class="mb-0">危险操作</h5>
            </div>
            <div class="card-body">
                <p class="text-danger">删除此用户将永久移除其账号和所有相关数据，包括文章。此操作不可撤销。</p>
                <a href="{{ url_for('admin.delete_user', id=user.id) }}" class="btn btn-danger" onclick="return confirm('确定要删除此用户吗？此操作不可撤销，用户的所有文章也将被删除。');">删除用户</a>
            </div>
        </div>
        {% endif %}
    </div>
</div>
{% endblock %}